home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK1.toast / Development Kits (Disc 1) / Apple Game Sprockets / More Sprocket Examples 1.0 / DroneZone Sources / DZDisplay.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-12  |  20.6 KB  |  766 lines  |  [TEXT/CWIE]

  1. /*
  2.  *    File:        DZDisplay.c
  3.  *
  4.  *    Contents:    Handles the window and its contents.
  5.  *
  6.  *    Copyright © 1996 Apple Computer, Inc.
  7.  */
  8.  
  9. #ifndef USE_DRAW_SPROCKET
  10.     #define USE_DRAW_SPROCKET        1
  11. #endif
  12.  
  13. #include <assert.h>
  14.  
  15. #include <Fonts.h>
  16. #include <Quickdraw.h>
  17. #include <Windows.h>
  18.  
  19. #include <QD3D.h>
  20. #include <QD3DCamera.h>
  21. #include <QD3DDrawContext.h>
  22. #include <QD3DGroup.h>
  23. #include <QD3DLight.h>
  24. #include <QD3DMath.h>
  25. #include <QD3DRenderer.h>
  26. #include <QD3DShader.h>
  27. #include <QD3DView.h>
  28.  
  29. #include "DZDisplay.h"
  30. #include "DZGame.h"
  31. #include "DZInput.h"
  32. #include "DZResource.h"
  33.  
  34. #if USE_DRAW_SPROCKET
  35.     #include "DrawSprocket.h"
  36. #endif
  37.  
  38.  
  39. #if USE_DRAW_SPROCKET
  40.     static DisplayObject    gDisplayObject                = NULL;
  41. #else
  42.     static WindowPtr        gDisplayWindow                = NULL;
  43. #endif
  44.  
  45. static Boolean                gDisplayActive                = false;
  46.  
  47. static PicHandle            gDisplayStartScreen            = NULL;
  48.  
  49. static TQ3ViewObject        gDisplayView                = NULL;
  50. static TQ3DrawContextObject    gDisplayDrawContext            = NULL;
  51. static TQ3RendererObject    gDisplayRenderer            = NULL;
  52. static TQ3CameraObject        gDisplayCamera                = NULL;
  53. static TQ3GroupObject        gDisplayLightGroup            = NULL;
  54. static TQ3LightObject        gDisplayAmbientLight        = NULL;
  55. static TQ3LightObject        gDisplayDirectionalLight    = NULL;
  56. static TQ3LightObject        gDisplayPointLight            = NULL;
  57. static TQ3ShaderObject        gDisplayIllumination        = NULL;
  58.  
  59. //• To get around an Interactive Renderer bug wherein Q3Renderer_Sync
  60. //•    crashes when called on a renderer that has not rendered.
  61. static Boolean                gDisplayHasRendered            = false;
  62.  
  63.  
  64. #if USE_DRAW_SPROCKET
  65.     static Boolean Display_IsBusy(
  66.         DisplayObject        inDisplayObject,
  67.         UInt32                inContext);
  68. #endif
  69.  
  70. static void Display_RenderImage(
  71.     void);
  72.     
  73. static void Display_BeginQD(
  74.     void);
  75.     
  76. static void Display_EndQD(
  77.     void);
  78.     
  79. static void Display_GetImageArea(
  80.     TQ3Area*                outArea);
  81.  
  82. static float Display_GetImageAspectRatio(
  83.     void);
  84.  
  85.  
  86. /* =============================================================================
  87.  *        Display_Init (external)
  88.  *
  89.  *    Creates the display window, initializes QD3D view etc. to draw in it.
  90.  * ========================================================================== */
  91. void Display_Init(
  92.     void)
  93. {
  94.     TQ3ViewAngleAspectCameraData    viewAngleCameraData;
  95.     TQ3PointLightData                pointLightData;
  96.     TQ3ColorRGB                        white = {1.0, 1.0, 1.0};
  97.     
  98.     // Grab the start screen
  99.     gDisplayStartScreen = GetPicture(kPictID_StartScreen);
  100.     
  101.     // Create the view
  102.     gDisplayView = Q3View_New();
  103.     
  104.     // Set up where to draw
  105.     #if USE_DRAW_SPROCKET
  106.     {
  107.         DisplayConfig                    theConfig;
  108.         DisplayConfig                    theActualConfig;
  109.         
  110.         // Create the display
  111.         theConfig.device                    = NULL;
  112.         theConfig.mode                        = 0;
  113.         theConfig.frequency                    = 0;
  114.         theConfig.width                        = 512;
  115.         theConfig.height                    = 384;
  116.         theConfig.colorNeeds                = kDisplayColorRequest;
  117.         theConfig.colorTable                = NULL;
  118.         theConfig.specialFlags                 = kDisplaySpecialBuffered | kDisplaySpecialQD3DAccel;
  119.         theConfig.specialFlagsInHW             = 0;
  120.         theConfig.frontBufferDepthMask        = kDisplayDepthMaskAll;
  121.         theConfig.backBufferDepthMask        = kDisplayDepthMask32 | kDisplayDepthMask16;
  122.         theConfig.frontBufferBestDepth        = 32;
  123.         theConfig.backBufferBestDepth        = 32;
  124.         theConfig.pageCount                    = 2;
  125.         theConfig.reserved1                    = 0;    
  126.         theConfig.reserved2                    = 0;    
  127.         FindGDeviceFromConfig(&theConfig);
  128.         NewDisplay(&theConfig, &gDisplayObject);
  129.         
  130.         GetDisplayActualConfig(gDisplayObject, &theActualConfig);
  131.         if (theActualConfig.frontBufferBestDepth < 16)
  132.         {
  133.             //• SHOULD PUT UP AN ALERT HERE SAYING SOMETHING LIKE
  134.             //•    "The best monitor setting that DroneZone could find was XXX."
  135.             //• "DroneZone runs much faster in Thousands or Millions of Colors."
  136.             //• "You can run in Thousands or Millions of Colors if you expand"
  137.             //• "the Video RAM on your display card, or if you switch to a smaller"
  138.             //• "video monitor."  (OK) (Quit)
  139.         }
  140.         
  141.         // DSp_SetDebugMode(true);
  142.         
  143.         FadeDisplayGamma(NULL, kSmoothFadeOut, NULL);
  144.         SetDisplayPlayState(gDisplayObject, kDisplayPlayStateActive);
  145.         //• SHOW SPLASH SCREEN HERE
  146.         FadeDisplayGamma(NULL, kSmoothFadeIn, NULL);
  147.         
  148.         #if 1
  149.         {
  150.             GWorldPtr                        theGWorld;
  151.             PixMapHandle                    pixMapHandle;
  152.             TQ3PixmapDrawContextData        pixmapDrawContextData;
  153.             // Create the draw context
  154.             GetDisplayBackBuffer(gDisplayObject, &theGWorld);
  155.             pixMapHandle = GetGWorldPixMap(theGWorld);
  156.             
  157.             pixmapDrawContextData.drawContextData.clearImageMethod    = kQ3ClearMethodWithColor;
  158.             pixmapDrawContextData.drawContextData.clearImageColor.a    = 1.0;
  159.             pixmapDrawContextData.drawContextData.clearImageColor.r    = 0.0;
  160.             pixmapDrawContextData.drawContextData.clearImageColor.g    = 0.0;
  161.             pixmapDrawContextData.drawContextData.clearImageColor.b    = 0.0;
  162.             pixmapDrawContextData.drawContextData.paneState         = kQ3False;
  163.             pixmapDrawContextData.drawContextData.maskState         = kQ3False;
  164.             pixmapDrawContextData.drawContextData.doubleBufferState    = kQ3False;
  165.             
  166.             pixmapDrawContextData.pixmap.image        = GetPixBaseAddr(pixMapHandle);
  167.             pixmapDrawContextData.pixmap.width         = theConfig.width;
  168.             pixmapDrawContextData.pixmap.height        = theConfig.height;
  169.             pixmapDrawContextData.pixmap.rowBytes    = (*pixMapHandle)->rowBytes & 0x00003FFF;
  170.             pixmapDrawContextData.pixmap.pixelSize    = theActualConfig.frontBufferBestDepth;
  171.             pixmapDrawContextData.pixmap.bitOrder    = kQ3EndianBig;
  172.             pixmapDrawContextData.pixmap.byteOrder    = kQ3EndianBig;
  173.             
  174.             switch (pixmapDrawContextData.pixmap.pixelSize)
  175.             {
  176.                 case 16:
  177.                     pixmapDrawContextData.pixmap.pixelType = kQ3PixelTypeRGB16;
  178.                 break;
  179.                 
  180.                 case 32:
  181.                     pixmapDrawContextData.pixmap.pixelType = kQ3PixelTypeRGB32;
  182.                 break;
  183.                 
  184.                 default:
  185.                     assert(0);
  186.             }
  187.             
  188.             gDisplayDrawContext = Q3PixmapDrawContext_New(&pixmapDrawContextData);
  189.         }
  190.         #else
  191.         {
  192.             TQ3MacDrawContextData            macDrawContextData;
  193.             
  194.             // Create the draw context
  195.             macDrawContextData.drawContextData.clearImageMethod        = kQ3ClearMethodWithColor;
  196.             macDrawContextData.drawContextData.clearImageColor.a    = 1.0;
  197.             macDrawContextData.drawContextData.clearImageColor.r    = 0.0;
  198.             macDrawContextData.drawContextData.clearImageColor.g    = 0.0;
  199.             macDrawContextData.drawContextData.clearImageColor.b    = 0.0;
  200.             macDrawContextData.drawContextData.maskState            = kQ3False;
  201.             macDrawContextData.drawContextData.paneState            = kQ3False;
  202.             macDrawContextData.drawContextData.doubleBufferState    = kQ3False;
  203.             macDrawContextData.library                                = kQ3Mac2DLibraryNone;
  204.             macDrawContextData.viewPort                                = NULL;
  205.             macDrawContextData.grafPort                                = NULL;
  206.             
  207.             GetDisplayBackBuffer(gDisplayObject, &macDrawContextData.window);
  208.         
  209.             gDisplayDrawContext = Q3MacDrawContext_New(&macDrawContextData);
  210.         }
  211.         #endif
  212.     }
  213.     #else
  214.     {
  215.         TQ3MacDrawContextData            macDrawContextData;
  216.         
  217.         // Create the window
  218.         gDisplayWindow = GetNewCWindow(kWindID_Display, NULL, (WindowPtr)(-1));
  219.         
  220.         // Create the draw context
  221.         macDrawContextData.drawContextData.clearImageMethod        = kQ3ClearMethodWithColor;
  222.         macDrawContextData.drawContextData.clearImageColor.a    = 1.0;
  223.         macDrawContextData.drawContextData.clearImageColor.r    = 0.0;
  224.         macDrawContextData.drawContextData.clearImageColor.g    = 0.0;
  225.         macDrawContextData.drawContextData.clearImageColor.b    = 0.0;
  226.         macDrawContextData.drawContextData.maskState            = kQ3False;
  227.         macDrawContextData.library                                = kQ3Mac2DLibraryNone;
  228.         macDrawContextData.drawContextData.paneState            = kQ3True;
  229.         macDrawContextData.drawContextData.doubleBufferState    = kQ3True;
  230.         macDrawContextData.window                                = (CGrafPtr) gDisplayWindow;
  231.         
  232.         Display_GetImageArea(&macDrawContextData.drawContextData.pane);
  233.     
  234.         gDisplayDrawContext = Q3MacDrawContext_New(&macDrawContextData);
  235.     }
  236.     #endif
  237.     
  238.     Q3View_SetDrawContext(gDisplayView, gDisplayDrawContext);
  239.     
  240.     // Create the renderer
  241.     #if 1
  242.         gDisplayRenderer = Q3Renderer_NewFromType(kQ3RendererTypeInteractive);
  243.         Q3InteractiveRenderer_SetDoubleBufferBypass(gDisplayRenderer, kQ3True);
  244.     #else
  245.         gDisplayRenderer = Q3Renderer_NewFromType(kQ3RendererTypeWireframe);
  246.     #endif
  247.     
  248.     Q3View_SetRenderer(gDisplayView, gDisplayRenderer);
  249.     
  250.     // Create the camera
  251.     viewAngleCameraData.cameraData.placement.cameraLocation.x    = 0.0;
  252.     viewAngleCameraData.cameraData.placement.cameraLocation.y    = 0.0;
  253.     viewAngleCameraData.cameraData.placement.cameraLocation.z    = 0.0;
  254.     viewAngleCameraData.cameraData.placement.pointOfInterest.x    = 1.0;
  255.     viewAngleCameraData.cameraData.placement.pointOfInterest.y    = 0.0;
  256.     viewAngleCameraData.cameraData.placement.pointOfInterest.z    = 0.0;
  257.     viewAngleCameraData.cameraData.placement.upVector.x            = 0.0;
  258.     viewAngleCameraData.cameraData.placement.upVector.y            = 1.0;
  259.     viewAngleCameraData.cameraData.placement.upVector.z            = 0.0;
  260.     viewAngleCameraData.cameraData.range.hither                    = 0.2;
  261.     viewAngleCameraData.cameraData.range.yon                    = 200.0;
  262.     viewAngleCameraData.cameraData.viewPort.origin.x            = -1.0;
  263.     viewAngleCameraData.cameraData.viewPort.origin.y            = 1.0;
  264.     viewAngleCameraData.cameraData.viewPort.width                = 2.0;
  265.     viewAngleCameraData.cameraData.viewPort.height                = 2.0;
  266.     viewAngleCameraData.fov                                        = 1.2;
  267.     viewAngleCameraData.aspectRatioXToY                            = Display_GetImageAspectRatio();
  268.  
  269.     gDisplayCamera = Q3ViewAngleAspectCamera_New(&viewAngleCameraData);
  270.     
  271.     Q3View_SetCamera(gDisplayView, gDisplayCamera);
  272.     
  273.     // Create the light group
  274.     gDisplayLightGroup = Q3LightGroup_New();
  275.     Q3View_SetLightGroup(gDisplayView, gDisplayLightGroup);
  276.     
  277.     // Create the point light
  278.     pointLightData.lightData.isOn        = kQ3True;
  279.     pointLightData.lightData.brightness    = 5.0;
  280.     pointLightData.lightData.color        = white;
  281.     pointLightData.castsShadows            = kQ3True;
  282.     pointLightData.attenuation            = kQ3AttenuationTypeInverseDistance;
  283.     pointLightData.location.x            = 0.0;
  284.     pointLightData.location.y            = 0.0;
  285.     pointLightData.location.z            = 0.0;
  286.     
  287.     gDisplayPointLight = Q3PointLight_New(&pointLightData);
  288.     
  289.     Q3Group_AddObject(gDisplayLightGroup, gDisplayPointLight);
  290.     
  291.     // Create the illumination shader
  292.     #if 1
  293.         gDisplayIllumination = Q3PhongIllumination_New();
  294.     #else
  295.         gDisplayIllumination = Q3LambertIllumination_New();
  296.     #endif
  297. }
  298.  
  299.  
  300. /* =============================================================================
  301.  *        Display_Exit (external)
  302.  *
  303.  *    Takes down the window, disposes of the QD3D stuff.
  304.  * ========================================================================== */
  305. void Display_Exit(
  306.     void)
  307. {
  308.     if (gDisplayHasRendered)
  309.     {
  310.         Q3Renderer_Sync(gDisplayRenderer, gDisplayView);
  311.     }
  312.     
  313.     #if USE_DRAW_SPROCKET
  314.         if(gDisplayObject != NULL)
  315.         {
  316.             FadeDisplayGamma(NULL, kSmoothFadeOut, NULL);
  317.             SetDisplayPlayState(gDisplayObject, kDisplayPlayStateInactive);
  318.             FadeDisplayGamma(NULL, kSmoothFadeIn, NULL);
  319.             DisposeDisplay(gDisplayObject);
  320.             gDisplayObject = NULL;
  321.         }
  322.     #else
  323.         if (gDisplayWindow != NULL)
  324.         {
  325.             DisposeWindow(gDisplayWindow);
  326.             gDisplayWindow = NULL;
  327.         }
  328.     #endif
  329.     
  330.     if (gDisplayView != NULL)
  331.     {
  332.         Q3Object_Dispose(gDisplayView);
  333.         gDisplayView = NULL;
  334.     }
  335.     
  336.     if (gDisplayDrawContext != NULL)
  337.     {
  338.         Q3Object_Dispose(gDisplayDrawContext);
  339.         gDisplayDrawContext = NULL;
  340.     }
  341.     
  342.     if (gDisplayRenderer != NULL)
  343.     {
  344.         Q3Object_Dispose(gDisplayRenderer);
  345.         gDisplayRenderer = NULL;
  346.     }
  347.     
  348.     if (gDisplayCamera != NULL)
  349.     {
  350.         Q3Object_Dispose(gDisplayCamera);
  351.         gDisplayCamera = NULL;
  352.     }
  353.     
  354.     if (gDisplayLightGroup != NULL)
  355.     {
  356.         Q3Object_Dispose(gDisplayLightGroup);
  357.         gDisplayLightGroup = NULL;
  358.     }
  359.     
  360.     if (gDisplayAmbientLight != NULL)
  361.     {
  362.         Q3Object_Dispose(gDisplayAmbientLight);
  363.         gDisplayAmbientLight = NULL;
  364.     }
  365.     
  366.     if (gDisplayDirectionalLight != NULL)
  367.     {
  368.         Q3Object_Dispose(gDisplayDirectionalLight);
  369.         gDisplayDirectionalLight = NULL;
  370.     }
  371.     
  372.     if (gDisplayPointLight != NULL)
  373.     {
  374.         Q3Object_Dispose(gDisplayPointLight);
  375.         gDisplayPointLight = NULL;
  376.     }
  377.     
  378.     if (gDisplayIllumination != NULL)
  379.     {
  380.         Q3Object_Dispose(gDisplayIllumination);
  381.         gDisplayIllumination = NULL;
  382.     }
  383. }
  384.  
  385.  
  386. /* =============================================================================
  387.  *        Display_Activate (external)
  388.  *
  389.  *    Handles activation and deactivation.
  390.  * ========================================================================== */
  391. void Display_Activate(
  392.     Boolean            inActivate)
  393. {
  394.     if (gDisplayActive != inActivate)
  395.     {
  396.         gDisplayActive = inActivate;
  397.         
  398.         Input_Activate(inActivate);
  399.         
  400.         if (!gDisplayActive)
  401.         {
  402.             Game_Silence();
  403.         }
  404.         
  405.         if (gDisplayHasRendered)
  406.         {
  407.             Q3Renderer_Sync(gDisplayRenderer, gDisplayView);
  408.         }
  409.         
  410.         Display_DrawGrow();
  411.     }
  412. }
  413.  
  414.  
  415. /* =============================================================================
  416.  *        Display_IsActive (external)
  417.  *
  418.  *    Returns true if the game is active.
  419.  * ========================================================================== */
  420. Boolean Display_IsActive(
  421.     void)
  422. {
  423.     #if USE_DRAW_SPROCKET
  424.         return true;
  425.     #else
  426.         return gDisplayActive;
  427.     #endif
  428. }
  429.  
  430.  
  431. /* =============================================================================
  432.  *        Display_DrawGrow (external)
  433.  *
  434.  *    Draws the grow box.
  435.  * ========================================================================== */
  436. void Display_DrawGrow(
  437.     void)
  438. {
  439. #if !USE_DRAW_SPROCKET
  440.     Rect                bounds;
  441.     
  442.     SetPort(gDisplayWindow);
  443.     
  444.     // Erase the horizontal part
  445.     bounds = gDisplayWindow->portRect;
  446.     bounds.top = bounds.bottom-15;
  447.     
  448.     EraseRect(&bounds);
  449.     
  450.     // Draw the grow box, but only the horizontal scroll stuff
  451.     ClipRect(&bounds);
  452.     DrawGrowIcon(gDisplayWindow);
  453.     ClipRect(&gDisplayWindow->portRect);
  454. #endif
  455. }
  456.  
  457.  
  458. /* =============================================================================
  459.  *        Display_DrawContents (external)
  460.  *
  461.  *    Draws the contents of the window.
  462.  * ========================================================================== */
  463. void Display_DrawContents(
  464.     void)
  465. {
  466.     TQ3Area            area;
  467.     FontInfo        fontInfo;
  468.     Rect            bounds;
  469.     Rect            bounds1;
  470.     
  471.     static Str255 pausedString = "\pPaused";  //• SHOULD COME FROM RESOURCE
  472.     
  473.     switch (Game_GetState())
  474.     {
  475.         case kGameState_Playing:
  476.             Display_RenderImage();
  477.         break;
  478.         
  479.         case kGameState_Paused:
  480.             Display_RenderImage();
  481.             Display_BeginQD();
  482.             Display_GetImageArea(&area);
  483.             
  484.             TextFont(geneva);
  485.             TextFace(bold);
  486.             TextSize(72);
  487.             
  488.             GetFontInfo(&fontInfo);
  489.             
  490.             MoveTo(
  491.                 area.min.x + 0.5*(area.min.x + area.max.x - StringWidth(pausedString)),
  492.                 area.min.y + 0.5*(area.min.y + area.max.y + fontInfo.ascent));
  493.             
  494.             ForeColor(redColor);
  495.             DrawString(pausedString);
  496.             ForeColor(blackColor);
  497.             
  498.             Display_EndQD();
  499.         break;
  500.         
  501.         case kGameState_Stopped:
  502.             Display_BeginQD();
  503.             
  504.             Display_GetImageArea(&area);
  505.             
  506.             bounds.top    = area.min.y;
  507.             bounds.left   = area.min.x;
  508.             bounds.bottom = area.max.y;
  509.             bounds.right  = area.max.x;
  510.             
  511.             PaintRect(&bounds);
  512.             
  513.             bounds1 = (*gDisplayStartScreen)->picFrame;
  514.             OffsetRect(
  515.                     &bounds1,
  516.                     ((bounds.right-bounds.left) - (bounds1.right-bounds1.left) >> 1) - bounds1.left,
  517.                     ((bounds.bottom-bounds.top) - (bounds1.bottom-bounds1.top) >> 1) - bounds1.top);
  518.             
  519.             DrawPicture(gDisplayStartScreen, &bounds1);
  520.             
  521.             Display_EndQD();
  522.         break;
  523.     }
  524. }
  525.  
  526.  
  527. /* =============================================================================
  528.  *        Display_RenderImage (internal)
  529.  *
  530.  *    Draws the 3D part of the window.
  531.  * ========================================================================== */
  532. void Display_RenderImage(
  533.     void)
  534. {
  535. #if USE_DRAW_SPROCKET
  536.     {
  537.         GWorldPtr theGWorld;
  538.         
  539.         GetDisplayBackBuffer(gDisplayObject, &theGWorld);
  540.         Q3MacDrawContext_SetWindow(gDisplayDrawContext, theGWorld);
  541.     }
  542. #endif
  543.  
  544.     Q3View_StartRendering(gDisplayView);
  545.     do
  546.     {
  547.         // Set up the rendering state
  548.         Q3InterpolationStyle_Submit(kQ3InterpolationStyleVertex, gDisplayView);
  549.         Q3BackfacingStyle_Submit(kQ3BackfacingStyleFlip, gDisplayView);
  550.         Q3FillStyle_Submit(kQ3FillStyleFilled, gDisplayView);
  551.         Q3Object_Submit(gDisplayIllumination, gDisplayView);
  552.         
  553.         // Draw the game contents
  554.         Game_Submit(gDisplayView);
  555.     }
  556.     while (Q3View_EndRendering(gDisplayView) == kQ3ViewStatusRetraverse);
  557.     
  558.     gDisplayHasRendered = true;
  559.  
  560. #if USE_DRAW_SPROCKET
  561.     SwapDisplayBuffers(gDisplayObject, Display_IsBusy, 0);
  562. #endif
  563. }
  564.  
  565.  
  566. /* =============================================================================
  567.  *        Display_IsBusy (internal)
  568.  *
  569.  *    Called by SwapDisplayBuffers (or a VBL task that it kicks off) to determine
  570.  *    if the back buffer is finished rendering.  Since QD3D can render
  571.  *    asynchronously through hardware, we have to let it finish.  Unfortunately,
  572.  *    the only way to do this is to hang here with a renderer Sync call.
  573.  * ========================================================================== */
  574. #if USE_DRAW_SPROCKET
  575.     Boolean Display_IsBusy(
  576.         DisplayObject        inDisplayObject,
  577.         UInt32                inContext)
  578.     {
  579.         Q3Renderer_Sync(gDisplayRenderer, gDisplayView);
  580.         return false;
  581.     }
  582. #endif
  583.  
  584.  
  585. /* =============================================================================
  586.  *        Display_Resize (external)
  587.  *
  588.  *    Called after the window has changed size.
  589.  * ========================================================================== */
  590. void Display_Resize(
  591.     void)
  592. {
  593. #if !USE_DRAW_SPROCKET
  594.     TQ3Area                    imageArea;
  595.     
  596.     // Reset the clip
  597.     ClipRect(&gDisplayWindow->portRect);
  598.     
  599.     // Change the draw context
  600.     Display_GetImageArea(&imageArea);
  601.     Q3DrawContext_SetPane(gDisplayDrawContext, &imageArea);
  602.     
  603.     // Change the camera aspect ratio
  604.     Q3ViewAngleAspectCamera_SetAspectRatio(gDisplayCamera, Display_GetImageAspectRatio());
  605. #endif
  606. }
  607.  
  608.  
  609. /* =============================================================================
  610.  *        Display_GetWindow (external)
  611.  *
  612.  *    Returns our window pointer.
  613.  * ========================================================================== */
  614. WindowPtr Display_GetWindow(
  615.     void)
  616. {
  617. #if USE_DRAW_SPROCKET
  618.     return NULL;
  619. #else
  620.     return gDisplayWindow;
  621. #endif
  622. }
  623.  
  624.  
  625. /* =============================================================================
  626.  *        Display_SetViewerPosition (external)
  627.  *
  628.  *    Moves the camera and point light based on the given info.
  629.  * ========================================================================== */
  630. void Display_SetViewerPosition(
  631.     const TQ3Point3D*        inPosition,
  632.     const TQ3Vector3D*        inDirection,
  633.     const TQ3Vector3D*        inUp)
  634. {
  635.     TQ3CameraPlacement        placement;
  636.     
  637.     assert(inPosition != NULL);
  638.     assert(inDirection != NULL);
  639.     assert(inUp != NULL);
  640.     
  641.     // Move the camera
  642.     placement.cameraLocation    = *inPosition;
  643.     placement.upVector            = *inUp;
  644.     
  645.     Q3Point3D_Vector3D_Add(inPosition, inDirection, &placement.pointOfInterest);
  646.     
  647.     Q3Camera_SetPlacement(gDisplayCamera, &placement);
  648.     
  649.     // Move the point light
  650.     Q3PointLight_SetLocation(gDisplayPointLight, inPosition);
  651. }
  652.  
  653.  
  654. /* =============================================================================
  655.  *        Display_GetViewerPosition (external)
  656.  *
  657.  *    Returns the current camera position.
  658.  * ========================================================================== */
  659. void Display_GetViewerPosition(
  660.     TQ3Point3D*                outPosition,
  661.     TQ3Vector3D*            outDirection,
  662.     TQ3Vector3D*            outUp)
  663. {
  664.     TQ3CameraPlacement        placement;
  665.     
  666.     assert(outPosition != NULL);
  667.     assert(outDirection != NULL);
  668.     assert(outUp != NULL);
  669.     
  670.     Q3Camera_GetPlacement(gDisplayCamera, &placement);
  671.     
  672.     *outPosition = placement.cameraLocation;
  673.     *outUp = placement.upVector;
  674.     
  675.     Q3Point3D_Subtract(
  676.             &placement.pointOfInterest,
  677.             &placement.cameraLocation,
  678.             outDirection);
  679. }
  680.  
  681.  
  682. /* =============================================================================
  683.  *        Display_GetImageArea (internal)
  684.  *
  685.  *    Sets outArea to the area occupied by the 3D image part of the window.
  686.  * ========================================================================== */
  687. void Display_GetImageArea(
  688.     TQ3Area*                outArea)
  689. {
  690.     assert(outArea != NULL);
  691.  
  692. #if USE_DRAW_SPROCKET
  693.     {
  694.         DisplayConfig theConfig;
  695.         
  696.         GetDisplayConfig(gDisplayObject, &theConfig);
  697.         
  698.         outArea->min.x = 0;
  699.         outArea->max.x = theConfig.width;
  700.         outArea->min.y = 0;
  701.         outArea->max.y = theConfig.height;
  702.     }
  703. #else    
  704.     outArea->min.x = gDisplayWindow->portRect.left;
  705.     outArea->max.x = gDisplayWindow->portRect.right;
  706.     outArea->min.y = gDisplayWindow->portRect.top;
  707.     outArea->max.y = gDisplayWindow->portRect.bottom-15;
  708. #endif
  709. }
  710.  
  711.  
  712. /* =============================================================================
  713.  *        Display_GetImageAspectRatio (internal)
  714.  *
  715.  *    Returns the aspect ratio of the area occupied by the 3D image part of the
  716.  *    window.
  717.  * ========================================================================== */
  718. float Display_GetImageAspectRatio(
  719.     void)
  720. {
  721.     TQ3Area                    imageArea;
  722.     
  723.     Display_GetImageArea(&imageArea);
  724.     
  725.     return (imageArea.max.x-imageArea.min.x) / (imageArea.max.y-imageArea.min.y);
  726. }
  727.  
  728.  
  729. /* =============================================================================
  730.  *        Display_BeginQD (internal)
  731.  *
  732.  *    Sets up for doing Quickdraw drawing.
  733.  * ========================================================================== */
  734. void Display_BeginQD(
  735.     void)
  736. {
  737.     if (gDisplayHasRendered)
  738.     {
  739.         Q3Renderer_Sync(gDisplayRenderer, gDisplayView);
  740.     }
  741.     
  742. #if USE_DRAW_SPROCKET
  743.     ••• TODO •••
  744. #else    
  745.     SetPort(gDisplayWindow);
  746. #endif
  747. }
  748.  
  749.  
  750. /* =============================================================================
  751.  *        Display_EndQD (internal)
  752.  *
  753.  *    Undoes what Display_BeginQD did.
  754.  * ========================================================================== */
  755. void Display_EndQD(
  756.     void)
  757. {
  758. #if USE_DRAW_SPROCKET
  759.     ••• TODO •••
  760. #else    
  761.     // do nothing
  762. #endif
  763. }
  764.  
  765.  
  766.